package com.zr.sms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.sms.model.Employee;
import com.zr.sms.service.FindEmpService;
import com.zr.sms.serviceimpl.FindEmpServiceImpl;


/**
 * 
 * @author Administrator 谭笑傲
 *
 */
public class AddEmpServlet extends HttpServlet{
	FindEmpService findemp = new FindEmpServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String ename = req.getParameter("ename");
		String esex = req.getParameter("esex");
		String ebirthday = req.getParameter("ebirthday");
		String ephone = req.getParameter("ephone");
		int esalary = Integer.parseInt(req.getParameter("esalary"));		
		
		 int rid = Integer.parseInt(req.getParameter("rid"));
		 String epsw = "123";
		 Employee e = new Employee();
		
		if(req.getParameter("rid").equals("1")||req.getParameter("rid").equals("2")){
			 e = new Employee(ename,epsw,esex,ebirthday,ephone,esalary,rid);
			 PrintWriter  pw =  resp.getWriter();
			 int flag  = findemp.addEmp(e);
			pw.write(String.valueOf(flag));
			}
		else{
			int cid = Integer.parseInt(req.getParameter("cid"));
				 e = new Employee(ename,epsw,esex,ebirthday,ephone,esalary,cid,rid);
				 PrintWriter  pw =  resp.getWriter();
				 int flag  = findemp.addEmpAll(e);
					 pw.write(String.valueOf(flag));
		}
	}
}